home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / PlayerPRO 4.4.1 / Filters Plugs / Smooth.c < prev    next >
C/C++ Source or Header  |  1995-04-16  |  2KB  |  87 lines

  1. /*    Smooth            */
  2. /*    v 0.2            */
  3. /*    1995 by Liane    */
  4.  
  5. //    Usage:
  6. //    Works like a low pass filter, removing high
  7. //    harmonics generated by a low sampling rate.
  8. //    Works on the selected part or all the waveform
  9. //    if there is no selection.
  10. //    Not very accurate, but pretty fast to write !!!
  11.  
  12. #include "MAD.h"
  13. #include "PPPlug.h"
  14.  
  15. #if defined(powerc) || defined(__powerc)
  16. enum {
  17.         PlayerPROPlug = kCStackBased
  18.         | RESULT_SIZE(SIZE_CODE( sizeof(OSErr)))
  19.         | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof( Ptr*)))
  20.         | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof( struct FileInstrData*)))
  21.         | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof( long)))
  22.         | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof( long)))
  23.         | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof( PPInfoPlug*)))
  24. };
  25.  
  26. ProcInfoType __procinfo = PlayerPROPlug;
  27. #else
  28. #include <A4Stuff.h>
  29. #endif
  30.  
  31. OSErr main(     Ptr                        *InstrumentPtr,
  32.                 struct FileInstrData    *theData,
  33.                 long                    SelectionStart,
  34.                 long                    SelectionEnd,
  35.                 PPInfoPlug                *thePPInfoPlug)
  36. {
  37. long    i, length, temp, prevtemp, nexttemp, work;
  38.  
  39.     if (SelectionStart == SelectionEnd) {
  40.         SelectionStart = 0;
  41.         SelectionEnd = theData->insSize;
  42.     }
  43.     length = SelectionEnd - SelectionStart - 1;
  44.  
  45.     switch( theData->amplitude)
  46.     {
  47.         case 8:
  48.         {
  49.             Ptr    SamplePtr = (*InstrumentPtr) + SelectionStart;
  50.             
  51.             prevtemp = *SamplePtr++;
  52.             temp = *SamplePtr++;
  53.             for( i = 1; i < length; i++)
  54.             {
  55.                 nexttemp = *SamplePtr--;
  56.                 
  57.                 work = ((prevtemp + nexttemp) + (temp * 6)) >> 3;
  58.         
  59.                 *SamplePtr++ = work;
  60.                 prevtemp = temp;
  61.                 temp = nexttemp;
  62.                 SamplePtr++;
  63.             }
  64.         } break;
  65.  
  66.         case 16:
  67.         {
  68.             short    *SamplePtr = (short*) *InstrumentPtr + (SelectionStart / 2);
  69.             
  70.             prevtemp = *SamplePtr++;
  71.             temp = *SamplePtr++;
  72.             for( i = 1; i < length / 2; i++)
  73.             {
  74.                 nexttemp = *SamplePtr--;
  75.                 
  76.                 work = ((prevtemp + nexttemp) + (temp * 6)) >> 3;
  77.         
  78.                 *SamplePtr++ = work;
  79.                 prevtemp = temp;
  80.                 temp = nexttemp;
  81.                 SamplePtr++;
  82.             }
  83.         } break;
  84.     }
  85.  
  86.     return noErr;
  87. }